// 引入托盘logo
const { logo_tray, path_config } = require("../constant/index");
// 引入
const { getConfig, setConfig } = require("../utils/getAndSetConfig");
const { app, Menu, dialog, Tray, nativeImage } = require("electron");

const path = require("path");

module.exports = markTray = (win) => {
  // 托盘
  let tray = null;

  if (app.isPackaged) {
    // 生产环境
    tray = new Tray(nativeImage.createFromPath(logo_tray));
  } else {
    // 测试环境
    tray = new Tray(path.join(__dirname, "../../public/img/logo-tray.ico"));
  }
  // 托盘名称
  tray.setToolTip("LOL助手");
  // 托盘菜单
  const contextMenu = Menu.buildFromTemplate([
    {
      label: "显示",
      click: () => {
        // win.show();
        win.setSkipTaskbar(false);
        win.restore();
      },
    },
    {
      label: "隐藏",
      click: () => {
        win.setSkipTaskbar(true);
        win.minimize();
      },
    },
    {
      label: "退出程序",
      click: () => {
        win.destroy();
        app.exit();
      },
    },
  ]);
  // 载入托盘菜单
  tray.setContextMenu(contextMenu);
  // 单击触发
  tray.on("click", () => {
    // 单击通知区图标实现应用的显示或隐藏

    // 窗口是否最小化
    if(win.isMinimized()) {
      
      win.setSkipTaskbar(false);
      win.restore();
    } else {
      win.setSkipTaskbar(true);
      win.minimize();
    }

  });



  return tray;
};
